<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>


    <script type="text/javascript">
        var arr = [1, 20, 30, 100, 1000];
        var avg = function(array) {
            var dValue = 0;
            for (i = 0; i < array.length; i++) {
                var num = array[i + 1] - array[i];
                if (array[i + 1] - array[i] == NaN) {
                    return
                } else if (dValue < num) {
                    dValue = num;
                }
            }
            return dValue;
        }

        document.write(avg(arr));
    </script>


</body>

</html>